function [out,lat,lon] = my_readncmap(path,name)
% [out, lat, lon] = my_readncmap(Path,VarName)
% ----------------------------------------------
% Discription: read data from nc file, and rotate 
% 	data to upper north and right east
% 	(suitable for variable dimension time,lat,lon in nc file)
% Input:
% 	Path, path to nc file
% 	VarName, string or char list, name of variable to load
% Output:
% 	out, mat file, up -> north, right -> east
% 	lat, latitude, from north to south
% 	lon, longitude, from west to east
    arguments
        path 
        name 
    end
    out = ncread(path,name);
    out = rot90(out);
    
    info = ncinfo(path);
    LatName = getVarName(info,'lat');
    LonName = getVarName(info,'lon');
    lat = ncread(path,LatName);
    lat = flip(lat);
    lon = ncread(path,LonName);
    
    function out = getVarName(info,name)
        VarList = {info.Variables.Name};
        pattern = strcat(name,'.*');
        Match = regexp(VarList,pattern,'match','once','ignorecase');
        out = Match((~ismissing(Match))&(~contains(Match,'2')));
        out = string(out);
    end
end
